home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 1992 August / info-mac-1992.iso / Source / 3D GrafSys / GrafSys.rel / Demo Sources / xfanyrot < prev    next >
Text File  |  1992-04-25  |  5KB  |  185 lines

  1. program TestGrafSys;
  2.  
  3. { 3d GrafSys Demo Program}
  4. { Vers. 1.1 }
  5. { (c) 1992 by Christian Franz }
  6.  
  7. { Program to demonstrate rotation around arbitrary achsis. The achsis always runs through }
  8. { the fighter's bow and the origin (point 30).  these two transformed points are used for the }
  9. { definition of the arbitrary achsis.                                                                                      }
  10.  
  11.  
  12.  
  13.     uses
  14. (* Matrix, Transformations, Data3D, ResourceAccess, Grafsys, Screen3D; *)
  15.         GrafSys, Screen3D;
  16.  
  17.     const
  18.         theWindowID = 400;
  19.         degree = 0.01745329; (* π/180 *)
  20.  
  21.     var
  22.         theWindow: WindowPtr;
  23.         theInt: INTEGER;
  24.         thePort: Graf3DPtr;
  25.         theMaster: Graf3DPtr;
  26.         Pyramid, Cube, xFighter: GrafObjPtr;
  27.         theEvent: EventRecord;
  28.         dx, dy, dz: integer;
  29.         r: Rect;
  30.         p1, p2: Vector4;
  31.  
  32.  
  33. (* Generate an object that looks like the famous x-Fighter in the world famous motion *)
  34. (* picture 'Star Wars'                                                                                                *)
  35. (**)
  36. (* Notice especially the definition of points 9 (bow) and 30                                         *)
  37.  
  38.     procedure makeFighter (var Obj: GrafObjPtr);
  39.         var
  40.             OK: boolean;
  41.             count: integer;
  42.  
  43.     begin
  44.         Obj := NewObject;
  45.         OK := AddPoint(Obj, -160, 0, 0, count);
  46.  
  47.         OK := AddPoint(Obj, -80, -10, 10, count);
  48.         OK := AddPoint(Obj, 110, -10, 10, count);
  49.         OK := AddPoint(Obj, 110, 10, 10, count);
  50.         OK := AddPoint(Obj, -80, 10, 10, count);
  51.  
  52.         OK := AddPoint(Obj, -80, -10, -10, count);
  53.         OK := AddPoint(Obj, 110, -10, -10, count);
  54.         OK := AddPoint(Obj, 110, 10, -10, count);
  55.         OK := AddPoint(Obj, -80, 10, -10, count);
  56.  
  57.         OK := AddLine(Obj, 1, 2);
  58.         OK := AddLine(Obj, 2, 3);
  59.         OK := AddLine(Obj, 3, 4);
  60.         OK := AddLine(Obj, 4, 5);
  61.         OK := AddLine(Obj, 6, 7);
  62.         OK := AddLine(Obj, 7, 8);
  63.         OK := AddLine(Obj, 8, 9);
  64.  
  65.         OK := AddLine(Obj, 9, 1);
  66.         OK := AddLine(Obj, 1, 5);
  67.         OK := AddLine(Obj, 1, 6); (* bow *)
  68.  
  69.         OK := AddPoint(Obj, 60, 10, 10, count); (* 10 *)
  70.         OK := AddPoint(Obj, 60, 80, 40, count);(* 11*)
  71.         OK := AddPoint(Obj, 100, 80, 40, count);(* 12 *)
  72.         OK := AddPoint(Obj, 100, 10, 10, count);(* 13 *)
  73.         OK := AddLine(Obj, 10, 11);
  74.         OK := AddLine(Obj, 11, 12);
  75.         OK := AddLine(Obj, 12, 13);
  76.  
  77.         OK := AddPoint(Obj, 50, 10, -10, count); (* 14 *)
  78.         OK := AddPoint(Obj, 50, 80, -40, count);(* 15*)
  79.         OK := AddPoint(Obj, 100, 80, -40, count);(* 16 *)
  80.         OK := AddPoint(Obj, 100, 10, -10, count);(* 17 *)
  81.         OK := AddLine(Obj, 14, 15);
  82.         OK := AddLine(Obj, 15, 16);
  83.         OK := AddLine(Obj, 16, 17);
  84.  
  85.         OK := AddPoint(Obj, 50, -10, 10, count); (* 18 *)
  86.         OK := AddPoint(Obj, 50, -80, 40, count);(* 19*)
  87.         OK := AddPoint(Obj, 100, -80, 40, count);(* 20 *)
  88.         OK := AddPoint(Obj, 100, -10, 10, count);(* 21 *)
  89.         OK := AddLine(Obj, 18, 19);
  90.         OK := AddLine(Obj, 19, 20);
  91.         OK := AddLine(Obj, 20, 21);
  92.  
  93.         OK := AddPoint(Obj, 50, -10, -10, count); (* 22 *)
  94.         OK := AddPoint(Obj, 50, -80, -40, count);(* 23*)
  95.         OK := AddPoint(Obj, 100, -80, -40, count);(* 24 *)
  96.         OK := AddPoint(Obj, 100, -10, -10, count);(* 25 *)
  97.         OK := AddLine(Obj, 22, 23);
  98.         OK := AddLine(Obj, 23, 24);
  99.         OK := AddLine(Obj, 24, 25);
  100.  
  101.         OK := AddPoint(Obj, 20, 80, 40, count); (* 26 *)
  102.         OK := AddPoint(Obj, 20, 80, -40, count);(* 27 *)
  103.         OK := AddPoint(Obj, 20, -80, 40, count);(* 28 *)
  104.         OK := AddPoint(Obj, 20, -80, -40, count);(* 29 *)
  105.         OK := AddLine(Obj, 26, 11);
  106.         OK := AddLine(Obj, 27, 15);
  107.         OK := AddLine(Obj, 28, 19);
  108.         OK := AddLine(Obj, 29, 23); (* weapons done *)
  109.  
  110.         OK := AddLine(Obj, 4, 8);
  111.         OK := AddLine(Obj, 3, 7);
  112.  
  113.         OK := AddPoint(Obj, 0, 0, 0, count); (* we need this point for free-rotate *)
  114.  (* punkt 30 *)
  115.     end;
  116.  
  117.     procedure getmouserot (var dx, dy, dz: integer);
  118.  
  119.         var
  120.             thePoint: point;
  121.  
  122.     begin
  123.         GetMouse(thePoint);
  124.         dx := 0;
  125.         dy := 0;
  126.         dz := 0;
  127.         if (thePoint.h < thePort^.center.h) and (thePoint.v < thePort^.center.v) then (* mouse in quadrant 1 -> xrot*)
  128.             begin
  129.                 dx := 5;
  130.             end;
  131.         if (thePoint.h > thePort^.center.h) and (thePoint.v < thePort^.center.v) then (* mouse in quadrant 2 -> yrot*)
  132.             begin
  133.                 dy := 5;
  134.             end;
  135.         if (thePoint.h > thePort^.center.h) and (thePoint.v > thePort^.center.v) then (* mouse in quadrant 3 -> zrot*)
  136.             begin
  137.                 dz := 5;
  138.             end;
  139.         if (thePoint.h < thePort^.center.h) and (thePoint.v > thePort^.center.v) then (* mouse in quadrant 4 -> idle*)
  140.             begin
  141.             end;
  142.         if button then
  143.             begin
  144.                 dx := -dx;
  145.                 dy := -dy;
  146.                 dz := -dz;
  147.             end;
  148.     end;
  149.  
  150.  
  151. begin
  152.     theWindow := GetNewWindow(theWindowID, nil, Pointer(-1));
  153.     SetPort(theWindow); (* draw in this window *)
  154.  
  155.     MoveTo(10, 10);
  156.     DrawString('3D Grafiksystem.             Object: X-Fighter.         (C) 1991 by C. Franz');
  157.     InitGrafSys;
  158.     NewGrafport(theWindow^.portRect, thePort);
  159.     MoveTo(10, thePort^.bottom - 0);
  160.     DrawString(' Press Button to Exit');
  161.     MakeFighter(xFighter);
  162.  
  163.     SetEye(TRUE, 0, 0, -100, 0, 0, 0, 1.512, FALSE);
  164.     ObjTranslate(xFighter, 0, 0, 100);
  165.     ObjRotate(xFighter, 0 * degree, 0 * degree, 0);
  166.     ObjScale(xFighter, 1, 1, 1);
  167.     SetAutoErase(xFighter, TRUE);
  168.     fDrawObject(xFighter);
  169.     repeat
  170.         GetMouseRot(dx, dy, dz);
  171.         SystemTask;
  172.         if (dx + dy + dz <> 0) then
  173.             begin
  174.                 fDrawObject(xfighter); (* draw Object *)
  175.                 ObjRotate(xFighter, dx * degree, dy * degree, dz * degree)
  176.             end
  177.         else (* instead of idle, we will freerotate it now! oh, yeah! *)
  178.             begin
  179.                 fDrawObject(xFighter);
  180.                 p1 := ObjPoint(xFighter, 1);
  181.                 p2 := ObjPoint(xFighter, 30);
  182.                 ObjFreeRotateArb(xFighter, p1, p2, 5 * degree);
  183.             end;
  184.     until Button;
  185. end.